package com.smartleanx.module.hrm.controller.admin.memorandum;

import com.smartleanx.framework.security.core.annotations.PreAuthenticated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.time.LocalDate;
import java.util.*;
import java.io.IOException;

import com.smartleanx.framework.common.pojo.PageParam;
import com.smartleanx.framework.common.pojo.PageResult;
import com.smartleanx.framework.common.pojo.CommonResult;
import com.smartleanx.framework.common.util.object.BeanUtils;
import static com.smartleanx.framework.common.pojo.CommonResult.success;

import com.smartleanx.framework.excel.core.util.ExcelUtils;

import com.smartleanx.framework.operatelog.core.annotations.OperateLog;
import static com.smartleanx.framework.operatelog.core.enums.OperateTypeEnum.*;

import com.smartleanx.module.hrm.controller.admin.memorandum.vo.*;
import com.smartleanx.module.hrm.dal.dataobject.memorandum.MemorandumDO;
import com.smartleanx.module.hrm.service.memorandum.MemorandumService;

@Tag(name = "管理后台 - 备忘录")
@RestController
@RequestMapping("/hrm/memorandum")
@Validated
public class MemorandumController {

    @Resource
    private MemorandumService memorandumService;


    @PostMapping("/create")
    @Operation(summary = "创建备忘录")
    @PreAuthenticated
    public CommonResult<Long> createMemorandum(@Valid @RequestBody MemorandumSaveReqVO createReqVOs) {
        return success(memorandumService.createMemorandum(createReqVOs));
    }


    @DeleteMapping("/delete")
    @Operation(summary = "删除备忘录")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthenticated
    public CommonResult<Boolean> deleteMemorandum(@RequestParam("id") Long id) {
        memorandumService.deleteMemorandum(id);
        return success(true);
    }


    @GetMapping("/getMemorandumList")
    @Operation(summary = "获取当前月和前后两月备忘录列表")
    @Parameter(name = "date", description = "日期", required = true, example = "yyyy-MM-dd")
    @PreAuthenticated
    public CommonResult<List<MemorandumListRespVO>> getMemorandumList(@RequestParam("date") String date){
        List<MemorandumListRespVO> list = memorandumService.getMemorandumList(date);
        return success(BeanUtils.toBean(list,MemorandumListRespVO.class));
    }

}
